<template>
  <div style="margin-top:30px;">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
<!--      <el-row>-->
<!--        <el-col :span="24">-->
<!--          <div class="grid-content bg-purple">-->
<!--            <el-form-item label="所属机构" prop="partyGroupCode" style="margin-right:15px">-->
<!--              <el-select v-model="form.partyGroupCode" placeholder="请选择机构" clearable style="width: 100%">-->
<!--                <el-option-->
<!--                  v-for="item in partyGroup"-->
<!--                  :key="item.code"-->
<!--                  :label="item.groupName"-->
<!--                  :value="item.code"-->
<!--                />-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </div>-->
<!--        </el-col>-->
<!--      </el-row>-->

      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="名称" prop="name" style="margin-right:15px">
              <el-input v-model="form.name" placeholder="请输入名称" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="类型"   style="margin-right:15px">
              <el-select v-model="form.type" style="width: 100%" placeholder="请选择类型" >
                <el-option
                  v-for="item in typeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="funcCancel">取 消</el-button>
      <el-button type="primary" @click="funcSubmit" :disabled="isDisable">确 定</el-button>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import request from '@/utils/request'
Vue.use(VXETable)
export default {
  name: 'UnitEdit',
  data() {
    return {
      isDisable:false,

      form: {
        code: '',
        name: '',
        type: '',
        // partyGroupCode:'',

        typeName:''
      },
      // partyGroup:[],
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' },

        ]
      },
      // 所属类型
      typeList: [
        { label: '单位', value: 0 },
        { label: '辅助单位', value: 1 }]
    }
  },
  created() {
    // this.findTypeList()
  },
  methods: {
    // changeType(e){
    //     this.form.type = e
    //     const item = this.typeList.find(item =>item.code === e)
    //     return this.form.typeName = item.name
    // },
    // 查询类型
    // findTypeList() {
    //   request({ url: `/arpa-basic-api/dict`, method: 'get', params: { type: 'unitType' }}).then(response => {
    //     this.typeList = response.data.records
    //   })
    // },
    // 获取页面信息
    getInfo(code) {
      request({ url: `/arpa-basic-api/unit/${code}`, method: 'get' }).then(response => {
        this.form = response.data
        // const item = this.typeList.find(item => Number(item.code) === this.form.type)
        // this.form.typeName = item.name
      })
    },
    // 提交
    funcSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.isDisable = true

          const rLoading = this.openLoading();
          const data = this.form
          request({ url: '/arpa-basic-api/unit', method: 'put', params: data }).then(response => {
            rLoading.close();
            this.$message({ message: response.msg, type: 'success' })
            this.$emit('fatherEditMethod')
            this.isDisable = false

            }).catch(() => this.isDisable = false)
        } else {
          return false
        }
      })
    },
    // 取消
    funcCancel() {
      this.$emit('fatherCancelMethod', 'edit')
    }

  }
}
</script>
<style lang="scss" scoped>
    .dialog-footer {
        margin:15px 0 15px 0;
        width: 175px;
        float: right;
    }
</style>
